package com.example.ribbondemo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class HelloWorldService {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${hi.url}")
    private String url;
    @HystrixCommand(fallbackMethod = "sorryHi")
    @GetMapping("/")
    public String hi(){
        System.out.println(url);

        return "这是通过 ribbon 方式获取的服务"+restTemplate.getForEntity(url,String.class).getBody();
    }

    public String sorryHi(){
        return "我是错误熔断后的信息";
    }
}
